package cmd

import (
	"context"
	"gf_ruoyi/internal/controller"
	"gf_ruoyi/internal/service"

	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/net/ghttp"
	"github.com/gogf/gf/v2/os/gcmd"
)

var (
	Main = gcmd.Command{
		Name:  "main",
		Usage: "main",
		Brief: "start http server",
		Func: func(ctx context.Context, parser *gcmd.Parser) (err error) {
			s := g.Server()
			s.Group("/", func(group *ghttp.RouterGroup) {
				// group.Middleware(ghttp.MiddlewareHandlerResponse)
				// group.Bind(
				// 	controller.Hello,
				// )
				group.Middleware(
					service.Middleware().Ctx,
					service.Middleware().CORS,
					ghttp.MiddlewareHandlerResponse,
				)
				// Register route handlers.
				group.Bind(
					// controller.Chat,
					controller.User,
				)
				// Special handler that needs authentication.
				group.Group("/", func(group *ghttp.RouterGroup) {
					group.Middleware(service.Middleware().Auth)
					// group.ALLMap(g.Map{
					// 	"/user/profile": controller.User.Profile,
					// })
				})
			})
			s.Run()
			return nil
		},
	}
)
